package com.itsu.app.controller;


import com.itsu.app.service.AppTestSoulService;
import com.itsu.interfaces.entity.TestSoulQuestionnaire;
import com.itsu.pojo.dto.AnswersDTO;
import com.itsu.pojo.vo.ReportVo;
import com.itsu.pojo.vo.SoundVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("testSoul")
public class TestSoulController {

    @Autowired
    AppTestSoulService appTestSoulService;

    @GetMapping
    public ResponseEntity getQuestionnaire() {
        List<TestSoulQuestionnaire> list = appTestSoulService.getQuestionnaire();
        return ResponseEntity.ok(list);
    }

    @PostMapping
    public ResponseEntity submitQuestionnaire(@RequestBody Map<String, Object> map) {
        ArrayList answers = (ArrayList)map.get("answers");
        Map o = (Map)answers.get(0);
        Integer questionId = (Integer) o.get("questionId");
        Integer optionId = (Integer) o.get("optionId");
        Map<String, Long> data = appTestSoulService.submitQuestionnaire(questionId, optionId);
        return ResponseEntity.ok(data);
    }

    @GetMapping("/report/{id}")
    public ResponseEntity getReport(@PathVariable Long id) {
        ReportVo vo = appTestSoulService.getReport(id);
        return ResponseEntity.ok(vo);
    }
}
